package com.shrio.dao.impl;

import com.shrio.dao.RoleDao;
import com.shrio.entity.Role;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by luojie on 2018/3/6.
 */
@Repository
public class RoleDaoImpl implements RoleDao {

    @Autowired
    private SessionFactory sessionFactory;

    private Session getCurrentSession() {
        return this.sessionFactory.openSession();
    }

    @Override
    public Role get(Long id) {
        return (Role) getCurrentSession().get(Role.class,id);
    }

    @Override
    public List<Role> findAll() {
        return null;
    }

    @Override
    public Long save(Role entity) {
        return (Long)getCurrentSession().save(entity);
    }

    @Override
    public void saveOrUpdate(Role entity) {
        getCurrentSession().saveOrUpdate(entity);
    }

    @Override
    public void delete(Long id) {
        Role person = get(id);
        getCurrentSession().delete(person);
    }
}
